package com.emit.security;//package com.emit.security;
//
//import com.emit.exception.BizException;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.authentication.AuthenticationProvider;
//import org.springframework.security.authentication.BadCredentialsException;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.stereotype.Service;
//
///**
// * @program: trade_lab_backend
// * @description 自定义用户检验类
// * @author: HYN
// * @create: 2021-06-17 13:09
// **/
//@Service
//public class AuthenticationProviderImpl implements AuthenticationProvider {
//
//
//    @Autowired
//    private MyUserDetailsServiceImpl myUserDetailsService;
//
//    /**
//     * 说明 重写用户校验类
//     * @param authentication
//     * @return
//     * @throws AuthenticationException
//     */
//    @Override
//    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
//        String username = authentication.getName();
//        String password = authentication.getCredentials().toString();
//        UserDetails userDetails = myUserDetailsService.loadUserByUsername(username);
//        if (userDetails==null){
//            throw new BizException("账号不存在！");
//        }
//        if (!new BCryptPasswordEncoder().matches(password, userDetails.getPassword())) {
//            throw new BizException("密码错误！");
//        }
//        return new UsernamePasswordAuthenticationToken(userDetails, userDetails.getPassword(), userDetails.getAuthorities());
//    }
//
//    /**
//     *说明 重写用户校验类
//     * @param aClass
//     * @return
//     */
//    @Override
//    public boolean supports(Class<?> aClass) {
//        return UsernamePasswordAuthenticationToken.class.equals(aClass);
//    }
//}
